/*
 * Created by JFormDesigner on Mon Jun 14 21:43:56 CST 2021
 */

package com.J1ay.carsys.gui.Emp;

import java.awt.event.*;
import com.J1ay.carsys.dao.BowerMapper;
import com.J1ay.carsys.gui.Emp.Dialog.CheckDialog;
import com.J1ay.carsys.gui.Emp.Dialog.Del;
import com.J1ay.carsys.gui.Welcome;
import com.J1ay.carsys.gui.tishi.Warning;
import com.J1ay.carsys.pojo.Bower;
import com.J1ay.carsys.service.EmpService;
import com.J1ay.carsys.service.Impl.EmpServiceImpl;
import com.J1ay.carsys.utils.MybatisUtils;

import java.awt.*;
import javax.swing.*;
import javax.swing.GroupLayout;

/**
 * @author Brainrain
 */
public class Check extends JFrame {
    Bower[] bowerList;
    int len =0;
    int EmpId;
    String Name;
    EmpService empService = new EmpServiceImpl();
    public Check(int empId,String name) {
        initComponents();
        this.label2.setText("工号:"+empId);
        this.label3.setText(name + "欢迎您~");
        EmpId = empId;
        Name = name;
    }

    private void button3ActionPerformed(ActionEvent e) {
        // TODO add your code here
        System.out.println(EmpId);
        new Main(EmpId,Name).start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void button4ActionPerformed(ActionEvent e) {
        // TODO add your code here
        new Welcome().start();
        // 关闭窗口
        JButton jButton = (JButton) e.getSource();
        Container container = jButton.getParent();
        while (!(container instanceof JFrame)) {
            container = container.getParent();
        }
        ((JFrame)container).dispose();
    }

    private void button2ActionPerformed(ActionEvent e) {
        // TODO add your code here
        int index = this.list1.getSelectedIndex();
        if (index == -1) {
            new Warning(this,"您还未选中想要审核的用户！").start();
        }
        else {
            Bower nowBower = bowerList[index];
            new CheckDialog(this,nowBower,EmpId).start();
            System.out.println(nowBower);
        }
    }

    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        scrollPane1 = new JScrollPane();
        list1 = new JList();
        button2 = new JButton();
        button3 = new JButton();
        label1 = new JLabel();
        label2 = new JLabel();
        label3 = new JLabel();
        button4 = new JButton();
        label5 = new JLabel();
        label6 = new JLabel();
        label7 = new JLabel();
        label8 = new JLabel();

        //======== this ========
        setTitle("\u5c0f\u6c7d\u8f66\u7ba1\u7406\u7cfb\u7edf");
        setResizable(false);
        Container contentPane = getContentPane();

        //======== scrollPane1 ========
        {
            scrollPane1.setViewportView(list1);
        }

        //---- button2 ----
        button2.setText("\u5ba1\u6838");
        button2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button2ActionPerformed(e);
            }
        });

        //---- button3 ----
        button3.setText("\u9996\u9875");
        button3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button3ActionPerformed(e);
            }
        });

        //---- label1 ----
        label1.setText("\u76ee\u524d\u6240\u5728\uff1a\u5ba1\u6838\u7ba1\u7406");

        //---- label2 ----
        label2.setText("\u5de5\u53f7\uff1a");

        //---- label3 ----
        label3.setText("\u6b22\u8fce\u60a8~");

        //---- button4 ----
        button4.setText("\u9000\u51fa");
        button4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                button4ActionPerformed(e);
            }
        });

        //---- label5 ----
        label5.setText("\u8eab\u4efd\u8bc1");

        //---- label6 ----
        label6.setText("\u540d\u5b57");

        //---- label7 ----
        label7.setText("\u7535\u8bdd");

        //---- label8 ----
        label8.setText("\u7f16\u53f7");

        GroupLayout contentPaneLayout = new GroupLayout(contentPane);
        contentPane.setLayout(contentPaneLayout);
        contentPaneLayout.setHorizontalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(contentPaneLayout.createSequentialGroup()
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 432, GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(button2))
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.TRAILING, false)
                                .addGroup(GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                                    .addGap(21, 21, 21)
                                    .addComponent(label8, GroupLayout.PREFERRED_SIZE, 53, GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                    .addComponent(label5, GroupLayout.PREFERRED_SIZE, 83, GroupLayout.PREFERRED_SIZE)
                                    .addGap(76, 76, 76)
                                    .addComponent(label6, GroupLayout.PREFERRED_SIZE, 76, GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(label7, GroupLayout.PREFERRED_SIZE, 74, GroupLayout.PREFERRED_SIZE))
                                .addGroup(GroupLayout.Alignment.LEADING, contentPaneLayout.createSequentialGroup()
                                    .addContainerGap()
                                    .addComponent(button3)
                                    .addGap(18, 18, 18)
                                    .addComponent(label1, GroupLayout.PREFERRED_SIZE, 141, GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(label2, GroupLayout.PREFERRED_SIZE, 89, GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(label3, GroupLayout.PREFERRED_SIZE, 99, GroupLayout.PREFERRED_SIZE)))
                            .addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(button4)))
                    .addContainerGap(12, Short.MAX_VALUE))
        );
        contentPaneLayout.setVerticalGroup(
            contentPaneLayout.createParallelGroup()
                .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(button3, GroupLayout.PREFERRED_SIZE, 26, GroupLayout.PREFERRED_SIZE)
                        .addComponent(label1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(button4, GroupLayout.DEFAULT_SIZE, 0, Short.MAX_VALUE)
                        .addComponent(label2, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(label3, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGap(18, 18, 18)
                    .addGroup(contentPaneLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
                        .addComponent(label8, GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addComponent(label7, GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addComponent(label5, GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE)
                        .addComponent(label6, GroupLayout.DEFAULT_SIZE, 27, Short.MAX_VALUE))
                    .addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(contentPaneLayout.createParallelGroup()
                        .addGroup(contentPaneLayout.createSequentialGroup()
                            .addComponent(scrollPane1, GroupLayout.PREFERRED_SIZE, 198, GroupLayout.PREFERRED_SIZE)
                            .addContainerGap())
                        .addGroup(GroupLayout.Alignment.TRAILING, contentPaneLayout.createSequentialGroup()
                            .addComponent(button2)
                            .addGap(101, 101, 101))))
        );
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents
    }

    //    表格数据
    public void setBoweTable(){
        bowerList = (Bower[]) empService.checkBowerList().getData();
        String[] data = new String[bowerList.length];
        for (int i = 0 ;i < bowerList.length;++i){
            data[i] = bowerList[i].tocheck();
        }
        this.list1.setListData(data);
        len = MybatisUtils.getSqlSession().getMapper(BowerMapper.class).countBower();
    }
    public void start() {
        this.setVisible(true);
        this.setBoweTable();
        this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JScrollPane scrollPane1;
    private JList list1;
    private JButton button2;
    private JButton button3;
    private JLabel label1;
    private JLabel label2;
    private JLabel label3;
    private JButton button4;
    private JLabel label5;
    private JLabel label6;
    private JLabel label7;
    private JLabel label8;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
